# import random
#
#
# def cdkey(count):
#     count = str(count)
#     if count == "":
#         print("输入不能为空！")
#     elif count.isdigit():
#         count = int(count)
#         for j in range(count):
#             ac_code = ""
#             for i in range(32):
#                 flag = random.randint(0, 1)
#                 if flag == 1:
#                     num = random.randint(48, 57)
#                 else:
#                     num = random.randint(65, 90)
#                 ac_code = ac_code + chr(num)
#             with open('cdkey.txt', 'a+') as f:
#                 f.write(f"{ac_code}\n")
#         print("激活码已写入cdkey.txt")
#     else:
#         print("请输入正确数值！")

import random
import time
# 自定义激活表列表
passwd_list= ['Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M',
              'q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m',
              0,1,2,3,4,5,6,7,8,9]
# list转换为string不能包含数字，如果包含需要进行如下转换，把数字转换为字符串
# str1 = "".join('%s' %id for id in passwd_list)
import string
str1 = string.ascii_uppercase+string.digits
print(str1)
# 随机生产激活码函数
def key_code(num):
    with open("激活码.txt", "w+") as f2:
        f2.read()
    for num in range(0, input1):
        str2 = "".join((random.sample(str1, 32)))
        time.sleep(0.5)
        print(f'第{num + 1}个激活码是：{str2}')
        with open("激活码.txt",'a+') as fp:
            fp.write(str2 + '\n')
    print("激活码生产完毕！")

# 主程序
print(f'{"激活码程序":#^50}')
while True:
    input1 = int(input(f'请输入你需要的激活码个数：'))
    if input1 == 0:
        print("输入有误，重新输入！")
    else:
        key_code(input1)
        break
with open("激活码.txt",'r+') as f:
    print(f.read())